package cn.jishiyu11.xeqb.utils

import android.graphics.Bitmap
import android.os.Environment

import java.io.File
import java.io.FileOutputStream
import java.io.IOException

object BitmapUtils {

    /**
     * 文件保存的路径
     */
    val FILE_PATH = Environment.getExternalStorageDirectory().path

    /**
     * 从本地SD卡获取网络图片，key是url的MD5值
     *
     * @return
     */
    fun getBitmap(bitmap: Bitmap) {
        try {
            val fileName = "jsy_ic_launcher.png"
            val file = File(FILE_PATH + "/" + fileName)
            if (!file.exists()) {
                file.mkdir()
            }
            file.createNewFile()
            val fOut = FileOutputStream(file)
            bitmap.compress(Bitmap.CompressFormat.PNG, 90, fOut)
            fOut.flush()
            fOut.close()
        } catch (e: IOException) {
            e.printStackTrace()
        }

    }
}
